<?php

require_once 'Basic.php';

class FormFieldPlate extends FormFieldType {
  
  public function __construct() {
    $this->htmlClass = "plateField";
    $this->inputSize = 15;
    $this->htmlId = null;
  }
  
  public function clearHtmlClass() {
    $this->htmlClass = "plateField";
  }

  public function getHtml($name, $value) {
    return $this->commonHtml($name, $value);
  }

  public function validate($input) {
    return FormFieldPlate::validatePlate($input);
  }
  
  public static function validatePlate($plate) {
    if(preg_match("%^[A-Za-z]{3}-?[0-9]{4}$%", $plate) === 1) {
      $plate = str_replace("-","",$plate);
      return true;
    }    
    else {
      return "A placa deve ser no formato AAA1111 ou AAA-1111. Foi passado \"<span class='userInput'>${plate}</span>\".";
    }
  }
  
}